package book.zone.controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: NDemeshchenko
 * Date: May 27, 2010
 * Time: 1:43:47 PM
 */
public class AddToCart extends HttpServlet {
    HttpSession session;
    ArrayList cart;

    @Override
    public void init() throws ServletException {
        super.init();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        session = req.getSession();
        cart = (ArrayList) session.getAttribute("cart");
//        Logger.out("cart.size() " +cart.size());
        if (session.getAttribute("cart") != null){
            cart.add(req.getParameter("product_id"));
            session.setAttribute("cart", cart);
        }
        resp.sendRedirect("/");
    }
}
